package com.jiutong.meipengdai.ui.activitys;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiutong.meipengdai.R;
import com.jiutong.meipengdai.base.BaseActivity;
import com.jiutong.meipengdai.entity.BankInfoRespond;
import com.jiutong.meipengdai.entity.BaseRespond;
import com.jiutong.meipengdai.http.model.interfaces.BankListBiz;
import com.jiutong.meipengdai.http.present.BankListPresent;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;
import com.jiutong.meipengdai.views.dialog.BaseDialog;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by suxi on 2017/6/20.
 */

public class BankCardInfoActivity extends BaseActivity implements BankListBiz {
    @Bind(R.id.rl_back)
    RelativeLayout rlBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_bank_name)
    TextView tvBankName;
    @Bind(R.id.tv_bank_num)
    TextView tvBankNum;
    @Bind(R.id.tv_danbi_xiane)
    TextView tvDanbiXiane;
    @Bind(R.id.tv_meiri_xiane)
    TextView tvMeiriXiane;
    @Bind(R.id.iv_bank_logo)
    ImageView ivBankLogo;
    @Bind(R.id.rl_out_bindding)
    RelativeLayout rlOutBindding;
    private String bankId;
    private BankListPresent bankListPresent;
    private String bankNumber;
    private BankInfoRespond respond;

    @Override
    public int getLayoutResouceId() {
        return R.layout.acitivity_bankcard_info;
    }

    @Override
    protected void initView() {
        super.initView();
        ButterKnife.bind(this);

        tvTitle.setText("我的银行卡");
        bankListPresent = new BankListPresent(mContext, this);
        bankListPresent.getBankInfo();
    }

    @Override
    protected void initDate(Bundle savedInstanceState) {
        super.initDate(savedInstanceState);
        Bundle bundle = getIntent().getExtras();
        bankId = bundle.getString("bankId");
    }

    @OnClick({R.id.rl_back, R.id.rl_out_bindding})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
            case R.id.rl_out_bindding:
//                Bundle bundle = new Bundle();
//                bundle.putString("bankNum", bankNumber);
//                bundle.putString("bankName", tvBankName.getText().toString());
//                bundle.putString("bankId", bankId);
//                openActivity(BankCardUnbindActivity.class, bundle);

                BaseDialog dialog = new BaseDialog.Builder().layResuorce(R.layout.dialog_bankcard_unbind)
                        .okViewClickEvent(R.id.tv_ok)
                        .cancelViewClickEvent(R.id.tv_cancel)
                        .dialogWidth(-2)
                        .gravityStyle(Gravity.CENTER)
                        .animResource(R.style.dialog_animation_fade)
                        .build();

                dialog.setOnDialogClickListener(new BaseDialog.OnDialogClickListener() {
                    @Override
                    public void onOkClick() {
                        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseRespond>() {
                            @Override
                            public void onNext(BaseRespond subjects) {
                                if ("200".equals(subjects.getResCode())) {
                                    finish();
                                } else {
                                    toastShortShow(subjects.getResDesc());
                                }
                            }

                            @Override
                            public void onError(Throwable e) {
                            }
                        };

//                        bankListPresent.delBannkInfo(onNextListener);
                    }

                    @Override
                    public void onOk2Click() {

                    }
                });

                dialog.show(getSupportFragmentManager(), TAG);
                break;
        }
    }

    @Override
    public String getBankNumber() {
        return bankNumber;
    }

    @Override
    public String getPhoneNo() {
        return null;
    }

    @Override
    public String getBankId() {
        return bankId;
    }

    @Override
    public void onSuccess(Object object) {
        respond = (BankInfoRespond) object;
        bankNumber = respond.getData().getBankNumber();
        tvBankName.setText(respond.getData().getBankName());
        tvBankNum.setText(bankNumber.substring(bankNumber.length() - 4));
        tvDanbiXiane.setText(respond.getData().getSingleQuota());
        tvMeiriXiane.setText(respond.getData().getEverydayQuota());
    }

    @Override
    public void onError(Throwable e) {

    }
}
